<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录 - {{ env('APP_NAME','Laravel') }}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{ asset('/static/bootstrap/css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ asset('/static/css/app.css') }}">
    <link rel="stylesheet" href="{{ asset('/static/css/login.css') }}">
{{--    <link rel="stylesheet" href="{{ asset('/static/css/override.css') }}">--}}
</head>
<body class="bg-gradient-primary">
<div class="layadmin-user-login layadmin-user-display-show app-login">
    <div class="app-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>{{ env('APP_NAME','Laravel') }}</h2>
            <p>欢迎登录后台管理系统</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body jing-form">
            <form id="form" action="">
                <div class="form-group">
                    <label class="layadmin-user-login-icon jing-icon jing-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="username" value="admin" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="form-control form-control-user">
                </div>
                <div class="form-group">
                    <label class="layadmin-user-login-icon jing-icon jing-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="password" value="admin" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="form-control form-control-user">
                </div>
                <div class="form-group">
                    <div class="row">
                        <div class="col-7">
                            <label class="layadmin-user-login-icon jing-icon jing-icon-vercode" for="LAY-user-login-vercode"></label>
                            <input type="text" name="captcha" maxlength="2" id="LAY-user-login-vercode" lay-verify="required" placeholder="验证码" class="form-control">
                        </div>
                        <div class="col-xs5">
                            <div class="verify-img">
                                <img src="{{ captcha_src('math') }}" alt="" onclick="this.src='/captcha/math?'+Math.random()" id="captcha_img">
                            </div>
                        </div>
                        @if($errors->has('captcha'))
                            <div class="col-xs5">
                                <p class="text-danger text-left"><strong>{{ $errors->first('captcha') }}</strong></p>
                            </div>
                        @endif
                    </div>
                </div>
                <div class="form-group">
                    <button type="button" class="btn btn-primary btn-user btn-block" id="submit">登 录</button>
                </div>
                <div class="form-group">

                </div>
                <input type="hidden" name="_token" value="{{ csrf_token() }}" />
            </form>
        </div>
    </div>
    <div class="jing-trans layadmin-user-login-footer">
        <p>&copy; {{ date('Y') }} 豪情<a href="http://www.laravel.com/" target="_blank">Laravel Admin</a></p>
    </div>
</div>
@include('admin.common._app_script')
<script src="{{ asset('/static/js/libs/core/packages/toast.js') }}"></script>
<script>
    App.cookie.remove('XSRF-TOKEN')

    $('#submit').on('click', function(){
        var data = $('#form').serialize()

        $.ajax({
            url: "{{ route('admin.login.post') }}",
            type: 'post',
            data: data,
            success: function (response) {
                if (response.code === 0) {
                    var redirect = response.data.redirect
                    App.toast('登录成功', function () {
                        if (!redirect) {
                            redirect = '{{ route('admin.index') }}'
                        }
                        location.href = redirect
                    })
                } else {
                    App.toast(response.msg)
                    $('#captcha_img').attr('src', '/captcha/math?' + Math.random())
                }
            },
            error: function (xhr, status, thrown) {
                if (xhr && xhr.responseText) {
                    // alert(xhr.responseJSON.errors.captcha)
                    var resText = JSON.parse(xhr.responseText)
                    var msg = resText.errors ? resText.errors.captcha[0] : resText.message
                    App.toast(msg)
                }
            }
        })
    })
    // App.loading.show()
</script>
</body>
</html>
